﻿using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Blazor;
using DevExpress.ExpressApp.Templates;

namespace EasyXaf.EntityDesigner;

public class EntityDesignerBlazorApplication : BlazorApplication
{
    public EntityDesignerBlazorApplication()
    {
        ApplicationName = "实体设计器";
        CheckCompatibilityType = CheckCompatibilityType.DatabaseSchema;
        DatabaseVersionMismatch += EntityDesignerBlazorApplication_DatabaseVersionMismatch;
    }

    protected override IFrameTemplate CreateDefaultTemplate(TemplateContext context)
    {
        if (context.Name == "ApplicationWindowContext")
        {
            return new DesignerApplicationWindowTemplate();
        }
        return base.CreateDefaultTemplate(context);
    }

    protected override void OnSetupStarted()
    {
        base.OnSetupStarted();
        DatabaseUpdateMode = DatabaseUpdateMode.UpdateDatabaseAlways;
    }

    private void EntityDesignerBlazorApplication_DatabaseVersionMismatch(object sender, DatabaseVersionMismatchEventArgs e)
    {
        e.Updater.Update();
        e.Handled = true;
    }
}
